import { createAlova } from 'alova';
import adapterFetch from 'alova/fetch';


const baseUrl = `http://xxx`

const alovaInstance = createAlova({
    baseURL:baseUrl,
    requestAdapter: adapterFetch(),
    timeout: 3000,
    responded: response => response.json(),
    beforeRequest: method => {
        method.config.headers.Cookie = 'QTK=9d07ba74-b023-43c2-ac57-b386ca12426b'
    },
    cacheFor: 0,
});
const defaultConfig = {
    params:{},
    headers: {},
    timeout: 0,
    cacheFor: 0
  };
/**
 * 
 * @param {*} url 请求地址
 * @param {*} config 配置参数
 * @returns 
 */
export const alovaGet = (url,config = {}) => {
    const mergedConfig = { ...defaultConfig, ...config }
    return alovaInstance.Get(url,{ ...mergedConfig })
}

/**
 * 
 * @param {*} url 请求地址
 * @param {*} data 请求 body
 * @param {*} config 配置参数
 */
export const alovaPost = (url,data,config= {}) => {
    const mergedConfig = { ...defaultConfig, ...config }
    return alovaInstance.Post(url,data,{ ...mergedConfig })
}
/**
 * 
 * @param {*} url 请求地址
 * @param {*} data 请求 body
 * @param {*} config 配置参数
 */
export const alovaPUT = (url,data,config= {}) => {
    const mergedConfig = { ...defaultConfig, ...config }
    return alovaInstance.Put(url,data,{ ...mergedConfig })
}
/**
 * 
 * @param {*} url 请求地址
 * @param {*} data 请求 body
 * @param {*} config 配置参数
 */
export const alovDELETE = (url,data,config= {}) => {
    const mergedConfig = { ...defaultConfig, ...config }
    return alovaInstance.Delete(url,data,{...mergedConfig })
}
/**
 * 
 * @param {*} url 请求地址
 * @param {*} config 配置参数
 */
export const alovHEAD = (url,config= {}) => {
    const mergedConfig = { ...defaultConfig, ...config }
    return alovaInstance.Head(url,{ ...mergedConfig })
}

/**
 * 
 * @param {*} url 请求地址
 * @param {*} data 请求 body
 * @param {*} config 配置参数
 */
export const alovPATCH = (url,data,config= {}) => {
    const mergedConfig = { ...defaultConfig, ...config }
    return alovaInstance.Patch(url,data,{ ...mergedConfig })
}
/**
 * 
 * @param {*} url 请求地址
 * @param {*} config 配置参数
 */
export const alovOPTIONS = (url,config= {}) => {
    const mergedConfig = { ...defaultConfig, ...config }
    return alovaInstance.Options(url,{ ...mergedConfig })
}